package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;

/**
 * Write a description of class SupplierController here.
 * 
 * @author Group1 
 * @version 2011-06-08
 */
public class SupplierController
{
    // instance variables - replace the example below with your own
    private SupplierContainer supplierContainer;
    private Supplier supplier;
    /**
     * Constructor for objects of class SupplierController
     */
    public SupplierController()
    {
        supplierContainer = supplierContainer.getInstance();
    }
    
    /**
     * Find a supplier
     * @param name Name of the Supplier to be found
     * @return Returns a Supplier
     */
    public Supplier findSupplier(String name) throws Exception
    {
        supplier = supplierContainer.findSupplierByName(name);
        if (supplier == null)
        {
            throw new Exception("No supllier found");
        }
        return supplier;
    }
    
    public Supplier findSupplier2(String name)
    {
        supplier = supplierContainer.findSupplierByName(name);
        return supplier;
    }
    
    /**
     * Creates a Supplier
     * @param name Name of Supplier
     * @param address Address of the Supplier
     * @param city City of the Supplier
     * @param ZIPCode ZIPCode date of the Supplier
     * @param phoneNumber Phone number of the Supplier
     * @param deliveryTime Delivery time of the Supplier
     */
    public void createSupplier(String name, String address, String city, int ZIPCode, int phoneNumber, String deliveryTime)
    {
        Supplier s = new Supplier(name, address, city, ZIPCode, phoneNumber, deliveryTime);
        supplierContainer.createSupplier(s);
    }
    
    /**
     * Delete a Supplier
     * @param throws Exception Throws an error further up in the system
     * @param name Name of the Supplier
     */
    public void deleteSupplier(String name) throws Exception
    {
        if(supplierContainer.findSupplierByName(name) == null)
        {
            throw new Exception("supplier not found");
        }
        else
        {
            supplierContainer.deleteSupplier(name);
           
        }
    }
    
    /**
     * Updates a suppliers data
     * @param name Name of the supplier that will be added
     * @param address Address of the supplier that will be added
     * @param city City of the supplier that will be added
     * @param ZIPCode ZIP Code of the supplier that will be added
     */
    public void updateSupplierAddressCityZIP(String name, String address, String city, int ZIPCode)
    {
        supplierContainer.updateSupplierAddressCityZIP(name, address, city, ZIPCode);
    }
    
    /**
     * Updates a suppliers data
     * @param name Name of the supplier that will be added
     * @param phoneNumber Phone number of the supplier that will be added
     * @param deliveryTime Delivery time of the supplier that will be added
     */
    public void updateSupplierPhoneDeliveryTime(String name, int phoneNumber, String deliveryTime)
    {
        supplierContainer.updateSupplierPhoneDeliveryTime(name, phoneNumber, deliveryTime);
    }
    
    /**
     * Lists all Suppliers
     */
    public ArrayList<Supplier> listAllSupplier()
    {
        return supplierContainer.listAllSupplier();
    }
    
}
